#include "DC_Motor_CD.h"

int Dir_Pin,Speed_Pin;

/*********************
 * ----初始化
*********************/
void DC_Motor_CD::Init(int dir_Pin,int speed_Pin)
{
  Dir_Pin = dir_Pin;
  Speed_Pin = speed_Pin;
  pinMode(Dir_Pin,OUTPUT);
  pinMode(Speed_Pin,OUTPUT);
}
/*********************
 * 马达
*********************/
void DC_Motor_CD::MD(int SUDU)
{
  if ( SUDU == 0 )
  {
    digitalWrite(Dir_Pin,LOW);
    analogWrite(Speed_Pin,0);
  }
  else if (SUDU > 0)
  {
    digitalWrite(Dir_Pin,HIGH);
    analogWrite(Speed_Pin,255-SUDU);
  }
  else
  {
    digitalWrite(Dir_Pin,LOW);
    analogWrite(Speed_Pin,SUDU);
  }
}
